const {createEditor, createToolbar} = window.wangEditor
var admin_map = $("#admin_map").val();
$('.wang-editor').each(function () {
    const filed = $(this).attr('data-filed');
    const value = $(this).attr('data-value');
    const editorConfig = {
        placeholder: '在此处填写内容...',
        filed: filed,
        MENU_CONF: {},
        onCreated(editor) {
            const html = editor.getHtml()
            if (html !== "<p><br></p>") {
                const filed = editor.getConfig().filed;
                $(".editor—" + filed).val(html)
            }
        },
        onChange(editor) {
            const html = editor.getHtml()
            if (html !== "<p><br></p>") {
                const filed = editor.getConfig().filed;
                $(".editor—" + filed).val(html)
            }
        }
    }
    editorConfig.MENU_CONF['uploadImage'] = {
        customBrowseAndUpload(insertFn) {
            var h = 630;
            if ($(window).height() < h) h = ($(window).height() - 20);
            parent.layer.open({
                type: 2,
                area: ['1000px', h + 'px'],
                btn: ['使用选中图片', '取消选择'],
                fix: false, //不固定
                maxmin: true,
                shadeClose: true,
                shade: 0.4,
                anim: 2,
                title: '选择图片',
                content: '/' + admin_map + '/gallery/open.html?c=10&n=选择图片&editor=1&v=&t=1',
                yes: function (index, layero) {
                    var body =  parent.layer.getChildFrame('body', index);
                    var a = body.find('#selectedUrl').val();
                    var n = a.split(',');
                    for (var i = 0; i < n.length; i++) {
                        insertFn(n[i])
                    }
                    parent.layer.close(index);
                }
            });
        }
    }

    editorConfig.MENU_CONF['uploadVideo'] = {
        // 上传视频的配置
        server: $("#uploadEditorVideo").val(),
        maxFileSize: 50 * 1024 * 1024, // 5M
        maxNumberOfFiles: 3,
        allowedFileTypes: ['video/*'],
    }

    const editor = createEditor({
        selector: '#editor-container-' + filed,
        html: value,
        config: editorConfig,
        mode: 'default', // or 'simple'
    })
    const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container-' + filed,
        // config: toolbarConfig,
        mode: 'default', // or 'simple'
    })


})